import $pacsApi from '../../api/pacs'

const state = {
  group: '',
  permissions: [],
  permissionsMapping: [
    'kscdsy', // 存档首页 -- 页面权限
    'ksyxlb', // 影像列表 -- 页面权限
    'ksyxjd', // 影像校对 -- 页面权限
    'kscdsz', // 存档设置 -- 页面权限
    'yxcxly', // 路由列表 -- 页面权限
    'yxpp',     // 影像匹配 -- 功能权限
    'yxxg',     // 影像修改 -- 功能权限
    'yxcf',     // 影像拆分 -- 功能权限
    'yxsc',     // 影像删除 -- 功能权限
    'yxjd',     // 影像校对 -- 功能权限
    'yxfs',     // 影像发送 -- 功能权限
    'yxdc',      // 影像导出 -- 功能权限
    'yxdr',      //影像导入 -- 功能权限
  ],
  systemid: '',
  deptInstitutionId: '',
  scope: '',
  firstEnter: true
}

const mutations = {
  SET_GROUP (state, payload) {
    state.group = payload
  },
  SET_PERMISSIONS (state, payload) {
    state.permissions = payload
  },
  SET_SYSTEMID (state, payload) {
    state.systemid = payload
  },
  SET_DEPTINSTITUTIONID (state, payload) {
    state.deptInstitutionId = payload
  },
  SET_SCOPE (state, payload) {
    state.scope = payload
  },
  SET_FIRSTENTER (state, payload) {
    state.firstEnter = payload
  },
}

const actions = {
  getPermissions({ commit, state }) { // 获取权限
    return new Promise((resolve, reject) => {
      $pacsApi.pacsApi.getPermissions().then(res => {
        let { code, data } = res
        if(code === 0) {
          commit('SET_GROUP', data.group)
          commit('SET_PERMISSIONS', data.permissions)
          resolve(data)
        }
      })
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
